package org.icdio.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.icdio.dao.Image;
import org.icdio.dao.impl.ImageImpl;
import org.icdio.entity.ImageEntity;

import net.sf.json.JSONObject;

/**
 * Servlet implementation class test2
 */
//@WebServlet("/test2")
public class test2 extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public test2() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");
		String req = request.getParameter("inputData");
//		String method = request.getParameter("method");
//		if(method.equals("show")) {
//			//查看serviceImpl
//		}
		Image getImage = new ImageImpl();
		ImageEntity  image = null;
		try {
			image = getImage.getImage(Integer.parseInt(req));
		} catch (NumberFormatException e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		JSONObject jsonObject = new JSONObject();
		jsonObject.put("id", image.getImage_id());
		jsonObject.put("imageUrl", image.getImage_url());
		jsonObject.put("fileName", image.getImage_name());
		jsonObject.put("size", image.getImage_size());
		jsonObject.put("type", image.getImage_type());
		System.out.println(jsonObject.toString());
		response.getWriter().write(jsonObject.toString());
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
